/**
 * @copyright 2018 indie Semiconductor
 *
 * This file is proprietary to indie Semiconductor.
 * All rights reserved. Reproduction or distribution, in whole
 * or in part, is forbidden except by express written permission
 * of indie Semiconductor.
 *
 * @file buckctrl_sfr.h
 */

#ifndef __BUCKCTRL_SFR_H__
#define __BUCKCTRL_SFR_H__

#include <stdint.h>

/* -------  Start of section using anonymous unions and disabling warnings  ------- */
#if   defined (__CC_ARM)
  #pragma push
  #pragma anon_unions
#elif defined (__ICCARM__)
  #pragma language=extended
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  #pragma clang diagnostic push
  #pragma clang diagnostic ignored "-Wc11-extensions"
  #pragma clang diagnostic ignored "-Wreserved-id-macro"
#elif defined (__GNUC__)
  /* anonymous unions are enabled by default */
#elif defined (__TMS470__)
  /* anonymous unions are enabled by default */
#elif defined (__TASKING__)
  #pragma warning 586
#elif defined (__CSMC__)
  /* anonymous unions are enabled by default */
#else
  #warning Not supported compiler type
#endif

/**
 * @brief A structure to represent Special Function Registers for BUCKCTRL.
 */
typedef struct {

  uint8_t  ENAREQ;                            /*<! Request to Enable the Buck +0x000 */
  uint8_t  _RESERVED_01[3];                   /* +0x001 */

  union {
    struct {
      uint8_t  PERIOD                   :  7; /*!< Buck Clock Period */
      uint8_t  SPREAD                   :  1; /*!< Clock Spreading Enable */
      uint8_t  SPREADP                  :  4; /*!< Buck Clock Period Spread on Plus Side */
      uint8_t  SPREADM                  :  4; /*!< Buck Clock Period Spread on Minus Side */
      uint16_t                          : 16; /*   (reserved) */
    };
    uint32_t WORD;
  } CLOCK; /* +0x004 */

  uint32_t LFSRVAL;                           /*<! LFSR initialisation value +0x008 */

  union {
    struct {
      uint8_t  BYPASSH                  :  8; /*!< Buck Bypass Signal High time */
      uint8_t  BYPASSL                  :  2; /*!< Buck Bypass signal Low time */
      uint8_t  STARTH                   :  1; /*!< Buck Start signal High time */
      uint8_t                           :  1; /*   (reserved) */
      uint8_t  ENAL                     :  2; /*!< time after ENAREQ goes low */
      uint8_t  DEBOUNCEOVERCURSTRBSEL   :  2; /*!< strobing point for debouncing the buck overcur signal */
      uint16_t                          : 16; /*   (reserved) */
    };
    uint32_t WORD;
  } TDELAY; /* +0x00C */

  union {
    struct {
      uint8_t  VDACTRIM                 :  8; /*!< TRIM code for VDAC */
      uint8_t  RAMPENA                  :  1; /*!< Enable the Ramp feature for VDAC */
      uint8_t                           :  3; /*   (reserved) */
      uint8_t  RAMPRATE                 :  2; /*!< Ramp Rate of vdac_3v3 to reach to set vdac_trim */
      uint8_t                           :  2; /*   (reserved) */
      uint8_t  RAMPVAL                  :  8; /*!< VDAC Ramp starting value */
      uint8_t                           :  8; /*   (reserved) */
    };
    uint32_t WORD;
  } VDACCODE; /* +0x010 */

  union {
    struct {
      union {
        struct {
          uint8_t  READY                :  1; /*!< Buck Ready interrupt enable */
          uint8_t  DISABLED             :  1; /*!< Buck Disable Complete interrupt enable */
          uint8_t  OVERCUR              :  1; /*!< Buck Overcurrent detected interrupt enable */
          uint8_t                       :  5; /*   (reserved) */
        };
        uint8_t BYTE;
      } ENABLE;
      union {
        struct {
          uint8_t  READY                :  1; /*!< Buck Ready interrupt clear */
          uint8_t  DISABLED             :  1; /*!< Buck Disable Complete interrupt clear */
          uint8_t  OVERCUR              :  1; /*!< Buck Overcurrent detected interrupt clear */
          uint8_t                       :  5; /*   (reserved) */
        };
        uint8_t BYTE;
      } CLEAR;
      union {
        struct {
          uint8_t  READY                :  1; /*!< Buck Ready interrupt status */
          uint8_t  DISABLED             :  1; /*!< Buck Disable Complete interrupt status */
          uint8_t  OVERCUR              :  1; /*!< Buck Overcurrent detected interrupt status */
          uint8_t                       :  5; /*   (reserved) */
        };
        uint8_t BYTE;
      } STATUS;
      union {
        struct {
          uint8_t  READY                :  1; /*!< Buck Ready interrupt active */
          uint8_t  DISABLED             :  1; /*!< Buck Disable Complete interrupt active */
          uint8_t  OVERCUR              :  1; /*!< Buck Overcurrent detected interrupt active */
          uint8_t                       :  5; /*   (reserved) */
        };
        uint8_t BYTE;
      } IRQ;
    };
    uint32_t WORD;
  } BUCKIRQ; /* +0x014 */

  union {
    struct {
      uint8_t  BUCKOFF                  :  8; /*!< BUCK off status Register */
      uint8_t  STATE                    :  8; /*!< Buck Controller State */
      uint16_t                          : 16; /*   (reserved) */
    };
    uint32_t WORD;
  } STATUS; /* +0x018 */

} BUCKCTRL_SFRS_t;

/* --------  End of section using anonymous unions and disabling warnings  -------- */
#if   defined (__CC_ARM)
  #pragma pop
#elif defined (__ICCARM__)
  /* leave anonymous unions enabled */
#elif (__ARMCC_VERSION >= 6010050)
  #pragma clang diagnostic pop
#elif defined (__GNUC__)
  /* anonymous unions are enabled by default */
#elif defined (__TMS470__)
  /* anonymous unions are enabled by default */
#elif defined (__TASKING__)
  #pragma warning restore
#elif defined (__CSMC__)
  /* anonymous unions are enabled by default */
#else
  #warning Not supported compiler type
#endif

/**
 * @brief The starting address of BUCKCTRL SFRS.
 */
#define BUCKCTRL_SFRS ((__IO BUCKCTRL_SFRS_t *)0x50010500)

#endif /* end of __BUCKCTRL_SFR_H__ section */


